#!/bin/sh

set -e

ARIA2_DIR="${HOME}/aria2"
ARIA2_RPC_SECRET="thefox.chen"

# 初始化配置目录
umask 002 \
  && mkdir -p "${HOME}/.aria2" \
  && : | gzip -c > "${HOME}/.aria2/aria2.session.gz"

# 下载最新的配置文件
curl -k -o "${HOME}/.aria2/aria2.conf" 'https://gitee.com/urain39/aria2conf-for-termux/raw/master/aria2.conf.example'

# 更改默认下载路径等
sed -i \
  -e "s|^\\(dir=\\).\{1,\}\$|\\1${ARIA2_DIR}|" \
  -e "s|^\\(rpc-secret=\\).\{1,\}\$|\\1${ARIA2_RPC_SECRET}|" \
  -e "s|/var/lib/aria2|${HOME}/.aria2|" \
  -e '$aenable-rpc=true' "${HOME}/.aria2/aria2.conf"

